/**===================================================================
 * This file for /back/product/product_add.jsp & product_edit.jsp  
 * Its goal is to validate fields.
 * @author this author
 * @date 2017-07-30 
 * ==================================================================== */
function saveOrUpdateProduct(form) {
  var name = $.trim($('#name').val());
  if (!name) {
	alert('Name is required.');
	return false;
  }
  if (name.length < 2 || name.length > 45) {
	alert("Name is required to be between 2 and 45 characters.");
    return false;	
  }
  var basePrice = $.trim($('#basePrice').val());
  if (!basePrice) {
	alert('Base Price is required.');
	return false;
  } 
  if (isNaN(basePrice)) {
	alert('Base Price is required to be numeric.');
	return false;
  }
  var marketPrice = $.trim($('#marketPrice').val());
  if (!marketPrice) {
	alert('Market Price is required.');
	return false;
    }
  if (isNaN(marketPrice)) {
	alert('Market Price is required to be numeric');  
	return false;  
  }
  var salesPrice = $.trim($('#salesPrice').val());
  if (!salesPrice) {
	alert('Sales Price is required.');
	return false;
  }
  if (isNaN(salesPrice)) {
	alert('Sales Price is required to be numeric.');
	return false;
  }
  var description = $.trim($('#description').val());
  if (!description) {
	alert('Description is required.');
	return false;
  }
  if (description.length > 255) {
	alert('Description is required to be no more than 255 characters.');  
    return false;
  }
  return true;
}
